
#include "moveframelessdialog.h"
#include <QMouseEvent>
#include <QPainter>

MoveFramelessDialog::MoveFramelessDialog(QWidget *parent)
        : QDialog(parent)
{
    // setObjectName("frameless_window");
    setWindowFlags(Qt::FramelessWindowHint);
    setAttribute(Qt::WA_TranslucentBackground);
}

MoveFramelessDialog::~MoveFramelessDialog()
{

}

void MoveFramelessDialog::mousePressEvent(QMouseEvent *event)
{
    if (event->buttons() == Qt::LeftButton)
    {
        last_position_ = event->globalPos() - pos();
        left_button_clicked_ = true;
    }
    QWidget::mousePressEvent(event);
}

void MoveFramelessDialog::mouseMoveEvent(QMouseEvent *event)
{
    if ((event->buttons() == Qt::LeftButton) && left_button_clicked_)
    {
        move(event->globalPos() - last_position_);
    }
    QWidget::mouseMoveEvent(event);
}

void MoveFramelessDialog::mouseReleaseEvent(QMouseEvent *event)
{
    left_button_clicked_ = false;
}
